import c.a2.b.f.e;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.customization.huangwm.dao.SW003.AssetInfoOperationDao;
import com.api.customization.huangwm.formmode.lims.UpdateLimsProcessApi;
import com.customization.huangwm.utils.DBTools;
import com.customization.huangwm.utils.HttpRequest;
import com.engine.fna.cmd.fnaEmbileMicroReport.GetInvoiceCloudTokenCmd;
import okhttp3.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import sun.misc.BASE64Encoder;
import weaver.conn.RecordSet;
import weaver.fna.invoice.utils.InvoiceCloudUtil;
import weaver.formmode.customjavacode.modeexpand.huangwm.SW003.PushToNC_bsinvman;
import weaver.formmode.customjavacode.modeexpand.huangwm.SW003.RegisterAssetsToRecords;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
import weaver.system.SysRemindWorkflow;

import java.io.File;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.Provider;
import java.security.Security;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author Huangwm
 * @Date 2022-05-06
 * @Version 1.0
 * @Description TODO
 **/
public class main {
    public static void main(String[] args) throws Exception {
        String rootPath = "E:\\WEAVER9\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");

        //System.err.println("09:01:53".substring(0,5));
//
//        Map<String,Object> params = new HashMap<>();
//        Map<String,Object> datas = new HashMap<>();
//        List<Map<String,Object>> list = new ArrayList<>();
//        Map<String,Object> test = new HashMap<>();
//        test.put("applicationQuantity",1+"");
//        test.put("SerialNumber",1+"");
//        test.put("depOfAsset",1+"");
//        test.put("depManager",1+"");//管理部門負責人
//        test.put("oldStatus",1+"");
//        test.put("reason","采購退貨");
//        test.put("amount",1+"");
//        test.put("mainAssetCode",1+"");
//        test.put("location",1+"");
//        test.put("locationDesc",1+"");
//        test.put("id","1");
//        list.add(test);
//        datas.put("requestNumber","No20230911");
//        datas.put("action","into");
//        datas.put("datas",list);
//        params.put("datas",datas);
//
//        JSONObject allParams = JSONObject.parseObject(JSONObject.toJSONString(params.get("datas")));
//        System.err.println(allParams);
//        JSONArray newdatas = new JSONArray();
//        try {
//            //datas = (List<Map<String, String>>)  requestParams.get("datas");
//            //20230911 注释 修改参数结构 将datas从List改为JSONArray
//            //datas = (List<Map<String, String>>) JSONObject.parse(requestParams.get("datas").toString());
//            newdatas = allParams.getJSONArray("datas");
//
//            for (int a=0;a<newdatas.size();a++) {
//                String params_id = newdatas.getJSONObject(a).getString("id");
//                System.err.println( newdatas.getJSONObject(a));
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        Double quantity1 = 0.0,quantity2 = 1.0;
//        System.err.println(quantity1!=0);
//        System.err.println(quantity2!=0);

//        Map<String,Object> detail = new HashMap<>();
//        detail.put("applicationQuantity",1);
//        detail.put("SerialNumber",1);
//        detail.put("depOfAsset",1);
//        detail.put("depManager",1);//管理部門負責人
//        detail.put("oldStatus",1);
//        detail.put("reason","采購退貨");
//        detail.put("amount",1);
//        detail.put("mainAssetCode",1);
//        detail.put("location",1);
//        detail.put("locationDesc",1);
//        detail.put("id","1");
//        detail.put("list",list);
//
//        System.err.println(detail.containsValue("采購退貨"));
//        System.err.println(detail.size());

//        List<String> list1 = new ArrayList<>();
//        list1.add("Code1");
//        list1.add("Code2");
//        list1.add("Code3");
//        list1.add("Code4");
//        list1.add("Code5");
//
//        List<String> list2 = new ArrayList<>();
//        list2.add("Code1");
//        list2.add("Code2");
//        list2.add("Code3");
//        list2.add("Code4");
//        list2.add("Code6");
//
//        List<String> list3 =  list1.stream().filter(p -> list2.contains((String) p)).collect(Collectors.toList());
//        System.out.println(list3.toString());
//        list1.removeAll(list3);
//        list2.removeAll(list3);
//        list1.addAll(list2);
//        System.out.println(list1.toString());

//        String otherParam = "field15285=2023-10-27&sqr=3&15289=你好吗&field15284=3";
//        Map<String,String> fields = new HashMap<>();
//        RecordSet rs = new RecordSet();
//        if(!otherParam.trim().isEmpty()){
//            String[] arr1 = otherParam.split("&");
//            for(int i=0;i< arr1.length;i++){
//                String  fieldString = arr1[i];
//                String[] fieldMap = fieldString.split("=");
//                //去掉field
//                String field = fieldMap[0].replace("field","");
//                String fieldname = getFieldName(field,rs,"-405");
//                if(!fieldname.isEmpty() && fieldname !=null){
//                    if(!fields.containsKey(fieldname)){
//                        fields.put(fieldname,fieldMap[1]);
//                    }
//                }
//            }
//
//        }

//        System.err.println(fields);
//        System.err.println(fields.size());
//        for (Map.Entry<String,String> entry : fields.entrySet()){
//            System.err.println(entry.getKey()+"  "+entry.getValue());
//        }

        String str = " Helow W O R D  ";
        String str2 = "A001-1";
        String str3 = "A001-1 ";
        String str4 = "A001-1&";
        String str5 = "A001哈";
        System.err.println(str.trim());
        System.err.println(validateString(str2));
        System.err.println(validateString(str3));
        System.err.println(validateString(str4));
        System.err.println(validateString(str5));
        //getToken("912775628168830977","912775632438755330","9b5a5e73321e49498805f7da52db2258");

    }

    public static boolean validateString(String input) {
        String pattern = "^[A-Za-z0-9- ]+$";
        return input.matches(pattern);
    }

    /**
     appId:发票云接口中的用户名
     cid:团队id
     secret：密码
     **/
    public static void getToken(String appId,String cid,String secret) {

        try {

            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost httpPost = new HttpPost("https://api.mypiaojia.com/api/invoiceApi/token/buildToken");
            CloseableHttpResponse httpResponse = null;
            RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(60000).setConnectTimeout(60000).setSocketTimeout(60000).build();
            httpPost.setConfig(config);
            //设置网关头信息
            httpPost.setHeader("content-type", "application/json");
            httpPost.setHeader("appkey", appId);
            long l = System.currentTimeMillis();
            Map<String, Object> map = new HashMap<>();
            map.put("role", 0);                  //见下表参数
            map.put("name", "系统管理员");
            map.put("userId", "1");         //见下表参数
            map.put("cid", cid);             //cid 见下表参数
            String s1 = JSONObject.toJSONString(map);
            String s2 = s1 + "&time=" + l + "&secret="+secret;    //secret 见下表参数
            String newMd5 = DigestUtils.md5Hex(s2);
            String s4 = s1 + "&time=" + l + "&md5=" + newMd5;
            //result={"data":"WEAPPNXCe0tfQjmRO1xmkJpIFYSyEDx8yFUfYB_q6ekqly3I","actionMsg":{"code":0,"message":"执行成功"}}，data值就是token
            StringEntity entity = new StringEntity(s4, ContentType.APPLICATION_JSON);
            httpPost.setEntity(entity);
            httpResponse = httpClient.execute(httpPost);
            org.apache.http.HttpEntity responseEntity = httpResponse.getEntity();
            String content = EntityUtils.toString(responseEntity, "UTF-8");
            //返回结果{"data":"WEAPPe8Ke9pFzz9fbZ3qCcN6itq1zLHCKOgPmXHz6uIg8eOg","actionMsg":{"code":0,"message":"执行成功"}}
            System.out.println("返回结果"+ content);

        }catch (Exception e) {
            e.printStackTrace();
        }
    }



}
